import { Injectable } from '@angular/core';
import moment from 'moment';

interface WorkerInfoObj {
	company: string;
	team: string;
	groups: string;
}

@Injectable({ providedIn: 'root' })
export class SearchParamUtils {

	dateRangePickerFormat(dateList: Date[]): any[] {
		if (dateList === null || dateList.length === 0) {
			return [null, null];
		}

		const startTime = moment(dateList[0]).format('YYYY-MM-DD');
		const endTime = moment(dateList[1]).format('YYYY-MM-DD');

		return [startTime, endTime];
	}

	workerInfoFormat(workerInfoIdList: string[]): WorkerInfoObj {
		let res = {} as WorkerInfoObj;

		if (workerInfoIdList !== null && workerInfoIdList.length > 0) {
			for (let i = 0; i < workerInfoIdList.length; i++) {
				switch (i) {
					case 0:
						res.company = workerInfoIdList[i];
						break;
					case 1:
						res.team = workerInfoIdList[i];
						break;
					case 2:
						res.groups = workerInfoIdList[i];
						break;
					default:
						break;
				}
			}
		}

		return res;
	}
}
